import LmToast from "./index.vue"
let instance = null
export default {
    install(Vue) {
        function generateInstance(options) {
            const Ctor = Vue.extend(LmToast)
            instance = new Ctor({
                propsData: options
            }).$mount(document.createElement('div'))
            if (options.onClose && Object.prototype.toString.call(options.onClose) === '[object Function]') {
                instance.$once("onClose", () => {
                    options.onClose()
                })
            }
            return instance
        }
        Vue.prototype.$toast = function (options) {
            instance && instance.$destroy()
            instance = generateInstance(options)
        }
    }
}